package com.shell.customer.base.rx;

import com.shell.bee.base.utils.SpringContextUtil;
import com.shell.customer.base.CusEvent;
import com.shell.customer.base.vo.CusRecVo;
import com.shell.customer.po.CusRec;
import com.shell.framework.rx.OnErrorNotImplementedSubscriber;
import com.shell.framework.utils.CommonDataUtil;
import com.shell.framework.utils.MessageSender;
import com.shell.governor.modules.message.keyword.SmsAuthPwdKeyword;
import com.shell.governor.user.vo.PubUserVo;
import org.springframework.stereotype.Component;

@Component
public class SaveCusMsgSubscriber extends OnErrorNotImplementedSubscriber<CusEvent> {
	public void onApplicationEvent(CusEvent event) {
		CusRecVo cusVo = event.getCusRecVo();
		if (!event.isAdd()) {
			return;
		}
		sendSms(cusVo, event.getUser());
	}

	private void sendSms(CusRec customerC, PubUserVo pubUser) {
		SmsAuthPwdKeyword keyword = new SmsAuthPwdKeyword();
		keyword.setCusName(customerC.getCusName());
		keyword.setLoginName(pubUser.getPhoneNo());
		keyword.setPassWord(pubUser.getUnencryptedPassword());
		keyword.setUrl(SpringContextUtil.getProperty("customer.website"));
		MessageSender.sendMessageToPhone(pubUser.getPhoneNo(), CommonDataUtil.getUserId(), "MT02109", keyword);
	}
}
